<%--
    Document   : loancollection
    Created on : Apr 6, 2011, 3:37:32 PM
    Author     : Dine
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
    <head>
        <sj:head jqueryui="true" jquerytheme="south-street" compressed="false"/>
        <jsp:include page="WEB-INF/fragments/globalHead.html"/>
        <title>Cashmate <s:property value="#session.branch.branchname"/> Loan Collection</title>
        <style type="text/css">
            #series,#seriesreq{
                width:80px;
            }
            #borrowercode,#borrowercodereq{
                width:140px;
            }
            #borrowername_widget,#borrowernamereq{
                width:205px!important;
                font-size: 13px!important;
            }
            #ornum,#ornumreq{
                width:150px;
            }
            #amount,#amountreq{
                width:120px;
            }

            #paymenttype,#paymenttypereq{
                width:81px;
            }

            #payment input{
                border:none;
                background-color: white;
            }

            #collinfo label{
                margin-right:7em;
            }

            #collinfo input{
                margin-right:5em;
            }

            #tbodysum input{
                border:none;
                background: transparent;
            }

            #bottomcoll button.ui-datepicker-trigger,#collinfo button.ui-datepicker-trigger{
                display:none;
            }

            #savedpayment{
                background-color: white;
            }

            #savedpayment td{
                width:150px;
            }


            #gview_collectionsGrid, #gview_depositsGrid,#gview_paymentsGrid{
                height:440px;
                overflow:auto;
            }

            .branchid,#sequence,#document,#totalc,#cashshort,#bankacctnum{
                background-color: #ddd;
            }


            #100pcs{
                background-color: #ddd;
            }

        </style> <!--main.jsp css-->
        <script type="text/javascript">
            $(document).ready(function(){
                var ctr = 0;
                $('.branchid').val("${sessionScope.branch.branchname}");
                $('#theContent').attr('overflow','');
                
                $('#printbtn').click(function(e){
                    alert('hahahha') 
                });
                
                
                $.subscribe('changeborrower', function(event,data) {
                    var bname = $('#borrowername_widget').val();
                    if(bname!=""){
                        $.ajax({
                            type:'POST',
                            url:"get-bcode",
                            data:"bname="+bname,
                            success:function(msg,textStatus,xhr){
                                $('#borrowercode').val(msg);
                                $('#ornum').focus();
                            },error:
                                function(xhr, textStatus, errorThrown){
                            }
                        });
                    }
                });
                
                $('.acode').bind('change',function(e){
                    e = e||window.event;
                    e.stopPropagation();
                    e.preventDefault();
                    var acode;
                    var id = this.id;

                    if(id=="acode"){
                        acode = $('#acode').val();
                        
                    }else if(id=="acodecoll"){
                        acode = $('#acodecoll').val();
                    }
                    $.ajax({
                        type:'POST',
                        url:"get-names",
                        data:"acode="+acode,
                        success:function(msg,textStatus,xhr){
                            var arr = msg.split("|");
                            var colid = arr[0].trim();
                            var colname = arr[1].trim();
                            
                            if(id=="acode"){
                                $('#ccode').val(colid);
                                $('#cname').val(colname);
                            }else if(id=="acodecoll"){
                                document.getElementById("errorcoll").style.display ="none";
                                $('#ccodecoll').val(colid);
                                $('#cnamecoll').val(colname);
                            }
                        }
                        ,error:
                            function(xhr, textStatus, errorThrown){
                            alert(errorThrown);
                        }
                    });
                });
                
                $('#searchbtn').click(function(e){
                    $('#searchdiv').css("display","inline");
                    if(${request.view==undefined}){
                        $('#btmbutton').css("margin-top","360px");
                    }else{
                        $('#bottomcoll').css("height","190px");
                    }
                });
                
                $('#borrowername_widget').keypress(function(e){
                    var code= (e.keyCode ? e.keyCode : e.which);
                    if(code==13){
                        $('#ornum').focus();
                    }                                  
                });
                                
                $('#ornum').keypress(function(e){
                    var code= (e.keyCode ? e.keyCode : e.which);
                    if(code==13){
                        $('#amount').focus();
                    }                                  
                });
                                
                $('#amount').keypress(function(e){
                    var code= (e.keyCode ? e.keyCode : e.which);
                    if(code==13){
                        $('#paymenttype').focus();
                    }                                  
                });
                                
                $('#paymenttype').focusout(function(e){
                    $('#cashdeposit').focus();
                });

                $('#paymenttype').keypress(function(e){
                    var code= (e.keyCode ? e.keyCode : e.which);
                    if(code==13){
                        $('#borrowercode').focus();
                    }                                  
                });

                $('#cashdeposit').keypress(function(e){
                    var code= (e.keyCode ? e.keyCode : e.which);
                    if(code==13){
                        $('#cshdepositnum').focus();
                    }                                  
                });
                                
                $('#cshdepositnum').keypress(function(e){
                    var code= (e.keyCode ? e.keyCode : e.which);
                    if(code==13){
                        $('#cashonhand').focus();
                    }                                  
                });
                
                $('.borrower').bind('focusout keypress',function(e){
                    var code= (e.keyCode ? e.keyCode : e.which);
                                    
                    if((code==13&&e.type =='keypress')||e.type=='focusout'){
                        e = e||window.event;
                        e.stopPropagation();
                        e.preventDefault();
                        var id= this.id;
                        var bcode = document.getElementById(id).value;
                        var acode = $('#acodecoll').val();
                        if(bcode!=""){
                            $.ajax({
                                type:'POST',
                                url:"get-bname",
                                data:"bcode="+bcode+"&acode="+acode,
                                success:function(msg,textStatus,xhr){
                                    if(msg.indexOf("exist")==-1){
                                        document.getElementById(id).style.color = "black";
                                        $('#borrowername_widget').val(msg);
                                        $('#borrowername_widget').focus();
                                        $('#errorinfo').css("display","none");
                                    }else{
                                        document.getElementById(id).style.color = "red";
                                        $('#borrowername_widget').val("");
                                        if($('#errorinfo').css("display")=="none"){
                                            $('#errorinfo').append(document.createTextNode("Borrower doesn't exist in this area"))
                                            $('#errorinfo').css("display","inline");
                                        }
                                    }
                                },error:
                                    function(xhr, textStatus, errorThrown){
                                    document.getElementById(id).style.color = "red";
                                    $('#borrowername_widget').val("");
                                }
                            });
                        }
                    }
                });
                
                $('#cashonhand').keyup(function(e){
                    var value = $('#cashonhand').val();
                    var totalc =$('#totalc').val();
                    var cashdeposit = $('#cashdeposit').val();
                    if(value!=""&&totalc!=""&&cashdeposit!=""){
                        value = parseFloat(removeCommas(value));
                        totalc= parseFloat(removeCommas(totalc));
                        cashdeposit = parseFloat(removeCommas(cashdeposit));
                        var diff= totalc-value-cashdeposit;
                        $('#cashshort').val(diff);
                    }
                });
                                
                $('#cashdeposit').keyup(function(e){
                    var value = $('#cashonhand').val();
                    var totalc =$('#totalc').val();
                    var cashdeposit = $('#cashdeposit').val();
                    if(value!=""&&totalc!=""&&cashdeposit){
                        value = parseFloat(removeCommas(value));
                        totalc= parseFloat(removeCommas(totalc));
                        cashdeposit = parseFloat(removeCommas(cashdeposit));
                        var diff= totalc-value-cashdeposit;
                        $('#cashshort').val(diff);
                    }
                });
                
               
                
                $('#amount').keyup(function(e){
                    $('#amount').val(Comma(this.value));
                });

                $('.money').keyup(function(e){
                    var id= this.id;
                    $('#'.concat(id)).val(Comma(this.value));
                });
                                
                function Comma(Num){
                    Num += '';
                    Num = Num.replace(',' , '');Num = Num.replace(',' , '');Num = Num.replace(',' , '');
                    Num = Num.replace(',' , '');Num = Num.replace(',' , '');Num = Num.replace(',' , '');
                    x = Num.split('.');
                    x1 = x[0];
                    x2 = x.length > 1 ? '.' + x[1] : '';
                    var rgx = /(\d+)(\d{3})/;
                    while (rgx.test(x1))
                        x1 = x1.replace(rgx, '$1' + ',' + '$2');
                    return x1 + x2;
                }
                function removeCommas( strValue ) {
                    var objRegExp = /,/g; //search for commas globally
                    return strValue.replace(objRegExp,'');
                }
               
                                
                                     
                var thousand,fivehundred,twohundred,onehundred,fifty,twenty,ten,five,one;
                               
                                
                function a(){
                    thousand = parseInt($('#1000amt').val());
                    fivehundred = parseInt($('#500amt').val());
                    twohundred =parseInt($('#200amt').val());
                    onehundred = parseInt($('#100amt').val());
                    fifty = parseInt($('#50amt').val());
                    twenty = parseInt($('#20amt').val());
                    ten = parseInt($('#10amt').val());
                    five = parseInt($('#5amt').val());
                    one = parseInt($('#1amt').val());
                                     
                    var total = thousand+fivehundred+twohundred+onehundred+fifty+twenty+ten+five+one;
                    $('#totaldenomination').val(total);
                }
                
               
                                
                $('#500pcs').keyup(function(e){
                    var val = $('#500pcs').val();
                    var amt = 500*val;
                    $('#500amt').val(amt);
                    a();
                });
                                
                $('#200pcs').keyup(function(e){ 
                    var val = $('#200pcs').val();
                    var amt = 200*val;
                    $('#200amt').val(amt);
                    a();
                });
                                
                $('#1000pcs').keyup(function(e){
                    var val = $('#1000pcs').val();
                    var amt = 1000*val;
                    $('#1000amt').val(amt);
                    a();
                });
                                
                $('#100pcs').keyup(function(e){
                    var val = $('#100pcs').val();
                    var amt = 100*val;
                    $('#100amt').val(amt);
                    a();
                });
                                
                $('#50pcs').keyup(function(e){
                    var val = $('#50pcs').val();
                    var amt = 50*val;
                    $('#50amt').val(amt);
                    a();
                });
                                
                $('#20pcs').keyup(function(e){
                    var val = $('#20pcs').val();
                    var amt = 20*val;
                    $('#20amt').val(amt);
                    a();
                });
                                
                $('#10pcs').keyup(function(e){
                    var val = $('#10pcs').val();
                    var amt = 10*val;
                    $('#10amt').val(amt);
                    a();
                });
                                
                $('#5pcs').keyup(function(e){
                    var val = $('#5pcs').val();
                    var amt = 5*val;
                    $('#5amt').val(amt);
                    a();
                });
                                
                $('#1pcs').keyup(function(e){
                    var val = $('#1pcs').val();
                    var amt = 1*val;
                    $('#1amt').val(amt);
                    a();
                });
            });
        </script> <!--main.jsp script-->
    </head>
    <body>

        <s:action name="query-privilege" executeResult="false" var="privilegeView" >
            <s:param name="privilege">v</s:param>
            <s:param name="moduleid">8</s:param>
            <s:param name="pagename">loancollection</s:param>
        </s:action>

        <s:action name="query-privilege" executeResult="false" var="privilegeCreate" >
            <s:param name="privilege">c</s:param>
            <s:param name="moduleid">8</s:param>
            <s:param name="pagename">loancollection</s:param>
        </s:action>

        <s:action name="query-privilege" executeResult="false" var="privilegeEdit" >
            <s:param name="privilege">e</s:param>
            <s:param name="moduleid">8</s:param>
            <s:param name="pagename">loancollection</s:param>
        </s:action>

        <s:action name="query-privilege" executeResult="false" var="privilegeDelete" >
            <s:param name="privilege">d</s:param>
            <s:param name="moduleid">8</s:param>
            <s:param name="pagename">loancollection</s:param>
        </s:action>

        <c:if test="${sessionScope.auth == null || sessionScope.auth == false}">
            <%--<jsp:forward page="index.jsp?auth=none"/>--%>
        </c:if>
        <s:div id="bodyContainer">
            <s:div id="logoContainer" cssClass="ui-widget-content ui-corner-all">
                <s:include value="WEB-INF/fragments/banner.jsp">
                    <s:param name="branch" value="#session.branch.branchname" />
                </s:include>
            </s:div>
            <jsp:include page="WEB-INF/fragments/top.jsp"/>
            <jsp:include page="WEB-INF/fragments/mainMenu.jsp?menu=Loan"/>
            <jsp:include page="WEB-INF/fragments/left.jsp?type=loan&innerType=loancollection&select1=subMenuLoanCollection&select2=loanCollectionSubMenu_${param.cat}"/>

            <s:div id="contentContainer" cssClass="ui-widget-content ui-corner-all">
                <h1 id="contentHeader" class="ui-state-default ui-corner-all"></h1>
                <s:div id="theContent" cssStyle="overflow:hidden">
                    <c:if test="${param.cat == 'coll'}">
                        <script type="text/javascript">
                            $('h1#contentHeader').html('<span id="level1">Collection</span>');
                            
                            $(document).ready(function(){
                                $('#document').val("Official Receipt");
                                var ctr=0;
                                
                                $('#postcollbtn').click(function(e){
                                    $('#status').val("post");
                                    document.bottom.submit(); 
                                });
                                
                                
                                $('#viewcollection').click(function(e){
                                    if($('#acodecoll').val()=="-1"){
                                        alert('Pls select an area code.');
                                    }else{
                                        if($('#acodecoll').val()!=""&&$('#ccodecoll').val()!=""&&$('#cnamecoll').val()!=""
                                            &&$('#datecoll').val()!=""&&$('#sequence').val()!=""
                                            && $('#document').val()!=""){

                                            var datecoll = $('#datecoll').val();
                                            var acode = $('#acodecoll').val();

                                            if(isDate(datecoll)==false){
                                                
                                            }else{
                                                document.viewcollect.submit();
                                            }
                                        }else{
                                            alert("Please complete the values for the fields.")
                                        }
                                    }
                                });
                                
                                $('#savebtn').click(function(e){
                                    if(($('#totalc').val()=="")||($('#cashdeposit').val()=="")||($('#cshdepositnum').val()=="")||($('#bankacctnum').val()=="")
                                        ||($('#cashonhand').val()=="")||($('#cashshort').val()=="")){
                                        alert("Pls complete the values for the fields");
                                    }
                                    else if($('#totaldenomination').val()!=removeCommas($('#cashonhand').val())){
                                        alert("Undeposited cash not equal with total amount");
                                    }else{
                                        $('#status').val("save");
                                        document.bottom.submit(); 
                                    }
                                });
                                
                                $('.nextbtn').bind('keypress keydown',function(e){
                                    var id = this.id;
                                    var code= (e.keyCode ? e.keyCode : e.which);
                                    if((e.type=='keypress'&&code==13)||(e.type=='keydown'&&code==9)){
                                        
                                        var series = $('#series').val();
                                        var borrowercode = $('#borrowercode').val();
                                        var borrower = $('#borrowername_widget').val();
                                        var ornum = $('#ornum').val();
                                        var amount = $('#amount').val();
                                        var paymenttype = $('#paymenttype').val();
                                        if(isNaN(removeCommas(amount))){
                                            $('#amount').css("color","red");
                                        }else{
                                            $('#amount').css("color","black");
                                            var num = series;
                                            num = parseInt(num)+1;
                                            var st = $('#'.concat(num));

                                            //end of array
                                            if(borrowercode!=""&&borrower!=""&&ornum!=""&&amount!=""&&paymenttype!=""){
                                                var scode=$('#series').val();

                                                var num = parseInt(scode)+1;
                                                scode = "#".concat(scode);

                                                if($(scode).length){        //new
                                                    $('#series').val(num);
                                                    $('#borrowercode').val("");
                                                    $('#borrowername_widget').val("");
                                                    $('#ornum').val("");
                                                    $('#amount').val("");
                                                    $('#borrowercode').focus();

                                                }else{          //save info to summary
                                                    ctr++;
                                                    var i = ctr;
                                                    var tr= document.createElement("tr");

                                                    tdseries= document.createElement("td");
                                                    tdbcode=document.createElement("td");
                                                    tdbname=document.createElement("td");
                                                    tdreceipt=document.createElement("td");
                                                    tdamt =document.createElement("td");
                                                    tdpayment =document.createElement("td");
                                                    tddelete = document.createElement("td");
                                                    tddelete.style.border = "none";
                                            
                                                    var lseries = document.createElement("input");
                                                    lseries.id = ctr;
                                                    lseries.setAttribute("name", "seriesname");
                                                    lseries.value=series;
                                                    lseries.readonly= "true";
                                                    lseries.style.width ="80px";
                                                    var lbcode = document.createElement("input");
                                                    lbcode.id = "BC".concat(ctr);
                                                    lbcode.setAttribute("name", "bcodename");
                                                    lbcode.value=borrowercode;
                                                    lbcode.readonly= "true";
                                                    lbcode.style.width ="140px";
                                                    var lbname = document.createElement("input");
                                                    lbname.id = "BN".concat(ctr);
                                                    lbname.setAttribute("name", "bnamename");
                                                    lbname.value=borrower;
                                                    lbname.readonly= "true";
                                                    lbname.style.width ="180px";
                                                    var lreceipt = document.createElement("input");
                                                    lreceipt.style.textAlign = "right";
                                                    lreceipt.id= "OR".concat(ctr);
                                                    lreceipt.setAttribute("name", "receiptname");
                                                    lreceipt.value=ornum;
                                                    lreceipt.readonly= "true";
                                                    lreceipt.style.width ="150px";
                                                    var lamt = document.createElement("input");
                                                    lamt.style.textAlign= "right";
                                                    lamt.id= "AMT".concat(ctr);
                                                    lamt.className = "amount";
                                                    lamt.setAttribute("name", "amountname");
                                                    lamt.value=amount;
                                                    lamt.readonly= "true";
                                                    lamt.style.width ="120px";
                                                    var lpayment= document.createElement("input");
                                                    lpayment.id= "PY".concat(ctr);
                                                    lpayment.setAttribute("name", "paymenttype");
                                                    lpayment.value=paymenttype;
                                                    lpayment.readonly= "true";
                                                    lpayment.style.width ="80px";
                                                    var ldelete = document.createElement("img");
                                                    ldelete.setAttribute("alt","deleterow");
                                                    ldelete.setAttribute("src","resources/images/close.gif");
                                                    
                                            
                                                    tdseries.appendChild(lseries);
                                                    tdbcode.appendChild(lbcode);
                                                    tdbname.appendChild(lbname);
                                                    tdreceipt.appendChild(lreceipt);
                                                    tdamt.appendChild(lamt);
                                                    tdpayment.appendChild(lpayment);
                                                    tddelete.appendChild(ldelete);
             
                                                    tr.appendChild(tdseries);
                                                    tr.appendChild(tdbcode);
                                                    tr.appendChild(tdbname);
                                                    tr.appendChild(tdreceipt);
                                                    tr.appendChild(tdamt);
                                                    tr.appendChild(tdpayment);
                                                    tr.appendChild(tddelete);

                                                    document.getElementById("tbodysum").appendChild(tr);
                                                    var amt=0;
                                                    for(var j =1;j<num;j++){
                                                        amt+=parseFloat(removeCommas($('#AMT'.concat(j)).val()));
                                                    }
                                                    $('#totalc').val(Comma(amt));
                                                    var value = $('#cashonhand').val();
                                                    var totalc =$('#totalc').val();
                                                    var cashdeposit = $('#cashdeposit').val();
                                                    if(value!=""&&totalc!=""&&cashdeposit){
                                                        value = parseFloat(removeCommas(value));
                                                        totalc= parseFloat(removeCommas(totalc));
                                                        cashdeposit = parseFloat(removeCommas(cashdeposit));
                                                        var diff= totalc-value-cashdeposit;
                                                        $('#cashshort').val(diff);
                                                    }
                                                            

                                                    $('#borrowercode').val("");
                                                    $('#borrowername_widget').val("");
                                                    $('#ornum').val("");
                                                    $('#amount').val("");
                                                    $('#series').val(i+1);
                                                            
                                                    if(e.type=='keydown'&&code==9){
                                                        e.preventDefault();
                                                        $('#cashdeposit').focus();
                                                    }else{
                                                        $('#borrowercode').focus();
                                                    }
                                                    $('#errorinfo').text("");
                                                    $('#errorinfo').css("display","none");
                                                        
                                                }
                                            }
                                            
                                        }
                                    }
                                });
                                
                                $('#viewall').click(function(e){
                                    $('#tbodysum').insertAfter($('#theadinput'));
                                });
                                
                                function Comma(Num){
                                    Num += '';
                                    Num = Num.replace(',' , '');Num = Num.replace(',' , '');Num = Num.replace(',' , '');
                                    Num = Num.replace(',' , '');Num = Num.replace(',' , '');Num = Num.replace(',' , '');
                                    x = Num.split('.');
                                    x1 = x[0];
                                    x2 = x.length > 1 ? '.' + x[1] : '';
                                    var rgx = /(\d+)(\d{3})/;
                                    while (rgx.test(x1))
                                        x1 = x1.replace(rgx, '$1' + ',' + '$2');
                                    return x1 + x2;
                                }
                                function removeCommas( strValue ) {
                                    var objRegExp = /,/g; //search for commas globally
                                    return strValue.replace(objRegExp,'');
                                }
                                                
                                var dtCh= "/";
                                var minYear=1900;
                                var maxYear=2100;

                                function isInteger(s){
                                    var i;
                                    for (i = 0; i < s.length; i++){   
                                        // Check that current character is number.
                                        var c = s.charAt(i);
                                        if (((c < "0") || (c > "9"))) return false;
                                    }
                                    // All characters are numbers.
                                    return true;
                                }

                                function stripCharsInBag(s, bag){
                                    var i;
                                    var returnString = "";
                                    // Search through string's characters one by one.
                                    // If character is not in bag, append to returnString.
                                    for (i = 0; i < s.length; i++){   
                                        var c = s.charAt(i);
                                        if (bag.indexOf(c) == -1) returnString += c;
                                    }
                                    return returnString;
                                }

                                function daysInFebruary (year){
                                    // February has 29 days in any year evenly divisible by four,
                                    // EXCEPT for centurial years which are not also divisible by 400.
                                    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
                                }
                                function DaysArray(n) {
                                    for (var i = 1; i <= n; i++) {
                                        this[i] = 31
                                        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
                                        if (i==2) {this[i] = 29}
                                    } 
                                    return this
                                }
                               

                                function isDate(dtStr){
                                    var daysInMonth = DaysArray(12)
                                    var pos1=dtStr.indexOf(dtCh)
                                    var pos2=dtStr.indexOf(dtCh,pos1+1)
                                    var strMonth=dtStr.substring(0,pos1)
                                    var strDay=dtStr.substring(pos1+1,pos2)
                                    var strYear=dtStr.substring(pos2+1)
                                    strYr=strYear
                                    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
                                    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
                                    for (var i = 1; i <= 3; i++) {
                                        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
                                    }
                                    month=parseInt(strMonth)
                                    day=parseInt(strDay)
                                    year=parseInt(strYr)
                                    if (pos1==-1 || pos2==-1){
                                        alert("The date format should be : mm/dd/yyyy")
                                        return false
                                    }
                                    if (strMonth.length<1 || month<1 || month>12){
                                        alert("Please enter a valid month")
                                        return false
                                    }
                                    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
                                        alert("Please enter a valid day")
                                        return false
                                    }
                                    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
                                        alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
                                        return false
                                    }
                                    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
                                        alert("Please enter a valid date")
                                        return false
                                    }
                                    return true
                                }
                               
                            });
                        </script>
                    <style>
                        #gview_collectionsGrid{
                            height:400px;
                            overflow:auto;
                        }
                    </style>

                    <jsp:include page="WEB-INF/fragments/loanCollectionContent.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'history'}">
                    <script type="text/javascript">
                        $(document).ready(function(){
                            $('h1#contentHeader').html('<span id="level1">Collection</span>');
                            $("#loanCollectionSubMenu_coll").addClass("ui-state-highlight");
                            
                            $('#searchbtn').click(function(e){
                                $('#searchdiv').css("display","inline");
                                $('#btmbutton').css("margin-top","10em");
                                
                            });
                        });
                    </script>
                    <jsp:include page="WEB-INF/fragments/collhistorycontent.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'dcr'}">
                    <script type="text/javascript">
                        $('h1#contentHeader').html('<span id="level1">Daily Collection Form</span>');
                    </script>
                    <jsp:include page="WEB-INF/fragments/dfccontent.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'savedcoll'}">
                    <style>
                        #savedbtmdetails input{
                            width:100px;
                        }

                        #savedbtmdetails label{
                            margin-right: 1em;
                        }

                        #1000amt,#500amt,#200amt,#100amt,#50amt,#20amt,#10amt,#5amt,#1amt{
                            background-color: #ddd;
                        }
                    </style>
                    <script type="text/javascript">
                        $(document).ready(function(){

                            $('h1#contentHeader').html('<span id="level1">Collection</span>');
                            $('#postcollbtn').click(function(e){
                                document.getElementById("postcollform").submit();
                            });
                            $("#loanCollectionSubMenu_coll").addClass("ui-state-highlight");
                            
                            $('#searchbtn').click(function(e){
                                $('#searchdiv').css("display","inline");
                                $('#bottomcoll').css("height","140px");
                                $('#btmbutton').css("margin-top","0px");
                            });
                            
                            
                            $('.nextbtn').bind('keypress keydown',function(e){
                                
                                var id = this.id;
                                var code= (e.keyCode ? e.keyCode : e.which);
                                if((e.type=='keypress'&&code==13)||(e.type=='keydown'&&code==9)){
                                    var series = $('#series').val();
                                    var ctr = parseInt(series);
                                    var borrowercode = $('#borrowercode').val();
                                    var borrower = $('#borrowername_widget').val();
                                    var ornum = $('#ornum').val();
                                    var amount = $('#amount').val();
                                    var paymenttype = $('#paymenttype').val();
                                    if(isNaN(removeCommas(amount))){
                                        $('#amount').css("color","red");
                                    }else{
                                        $('#amount').css("color","black");
                                        var num = series;
                                        num = parseInt(num)+1;
                                        var st = $('#'.concat(num));

                                        //end of array
                                        if(borrowercode!=""&&borrower!=""&&ornum!=""&&amount!=""&&paymenttype!=""){
                                            var scode=$('#series').val();

                                            var num = parseInt(scode)+1;
                                            scode = "#".concat(scode);

                                            if($(scode).length){        //new
                                                $('#series').val(num);
                                                $('#borrowercode').val("");
                                                $('#borrowername_widget').val("");
                                                $('#ornum').val("");
                                                $('#amount').val("");
                                                $('#borrowercode').focus();

                                            }else{          //save info to summary
                                                var i = ctr;
                                                var tr= document.createElement("tr");

                                                tdseries= document.createElement("td");
                                                tdbcode=document.createElement("td");
                                                tdbname=document.createElement("td");
                                                tdreceipt=document.createElement("td");
                                                tdamt =document.createElement("td");
                                                tdpayment =document.createElement("td");
                                                tddelete = document.createElement("td");
                                            
                                                var lseries = document.createElement("input");
                                                lseries.id = ctr;
                                                lseries.setAttribute("name", "seriesname");
                                                lseries.value=series;
                                                lseries.readonly= "true";
                                                lseries.style.width="80px";
                                                var lbcode = document.createElement("input");
                                                lbcode.id = "BC".concat(ctr);
                                                lbcode.setAttribute("name", "bcodename");
                                                lbcode.value=borrowercode;
                                                lbcode.readonly= "true";
                                                lbcode.style.width="140px";
                                                var lbname = document.createElement("input");
                                                lbname.id = "BN".concat(ctr);
                                                lbname.setAttribute("name", "bnamename");
                                                lbname.value=borrower;
                                                lbname.readonly= "true";
                                                lbname.style.width ="205px";
                                                var lreceipt = document.createElement("input");
                                                lreceipt.style.textAlign = "right";
                                                lreceipt.id= "OR".concat(ctr);
                                                lreceipt.setAttribute("name", "receiptname");
                                                lreceipt.value=ornum;
                                                lreceipt.readonly= "true";
                                                lreceipt.style.width="150px"
                                                var lamt = document.createElement("input");
                                                lamt.style.textAlign= "right";
                                                lamt.id= "AMT".concat(ctr);
                                                lamt.className = "amount";
                                                lamt.setAttribute("name", "amountname");
                                                lamt.value=amount;
                                                lamt.readonly= "true";
                                                lamt.style.width="120px";
                                                var lpayment= document.createElement("input");
                                                lpayment.id= "PY".concat(ctr);
                                                lpayment.setAttribute("name", "paymenttype");
                                                lpayment.value=paymenttype;
                                                lpayment.readonly= "true";
                                                lpayment.style.width = "81px";
                                                var ldelete = document.createElement("img");
                                                ldelete.setAttribute("alt","deleterow");
                                                ldelete.setAttribute("src","resources/images/close.gif");
                                            
                                                tdseries.appendChild(lseries);
                                                tdbcode.appendChild(lbcode);
                                                tdbname.appendChild(lbname);
                                                tdreceipt.appendChild(lreceipt);
                                                tdamt.appendChild(lamt);
                                                tdpayment.appendChild(lpayment);
                                                tddelete.appendChild(ldelete);
                                                    
                                                tr.appendChild(tdseries);
                                                tr.appendChild(tdbcode);
                                                tr.appendChild(tdbname);
                                                tr.appendChild(tdreceipt);
                                                tr.appendChild(tdamt);
                                                tr.appendChild(tdpayment);
                                                tr.appendChild(tddelete);

                                                document.getElementById("tbodysum2").appendChild(tr);
                                                var tamt=0;
                                                var amt =0;
                                                
                                                amt = removeCommas($('#AMT'.concat(ctr)).val());
                                                tamt=parseFloat($('#totalc').val())+parseFloat(amt);
                                                
                                                $('#totalc').val(Comma(tamt));
                                                var value = $('#cashonhand').val();
                                                var totalc =$('#totalc').val();
                                                var cashdeposit = $('#cashdeposit').val();
                                                if(value!=""&&totalc!=""&&cashdeposit){
                                                    value = parseFloat(removeCommas(value));
                                                    totalc= parseFloat(removeCommas(totalc));
                                                    cashdeposit = parseFloat(removeCommas(cashdeposit));
                                                    var diff= totalc-value-cashdeposit;
                                                    $('#cashshort').val(diff);
                                                }
                                                            

                                                $('#borrowercode').val("");
                                                $('#borrowername_widget').val("");
                                                $('#ornum').val("");
                                                $('#amount').val("");
                                                $('#series').val(i+1);
                                                            
                                                if(e.type=='keydown'&&code==9){
                                                    e.preventDefault();
                                                    $('#cashdeposit').focus();
                                                }else{
                                                    $('#borrowercode').focus();
                                                }
                                                $('#errorinfo').text("");
                                                $('#errorinfo').css("display","none");
                                                        
                                            }
                                        }
                                            
                                    }
                                }
                            });
                            
                            function Comma(Num){
                                Num += '';
                                Num = Num.replace(',' , '');Num = Num.replace(',' , '');Num = Num.replace(',' , '');
                                Num = Num.replace(',' , '');Num = Num.replace(',' , '');Num = Num.replace(',' , '');
                                x = Num.split('.');
                                x1 = x[0];
                                x2 = x.length > 1 ? '.' + x[1] : '';
                                var rgx = /(\d+)(\d{3})/;
                                while (rgx.test(x1))
                                    x1 = x1.replace(rgx, '$1' + ',' + '$2');
                                return x1 + x2;
                            }
                            function removeCommas( strValue ) {
                                var objRegExp = /,/g; //search for commas globally
                                return strValue.replace(objRegExp,'');
                            }
                            
                            var thousand,fivehundred,twohundred,onehundred,fifty,twenty,ten,five,one;
                            var total =0;
                               
                                
                            function compute(amount){
                                total = total + parseFloat($('#'.concat(amount,'amt')).val());
                                $('#totaldenomination').val(total);
                            }
                            
                            thousand = parseInt($('#1000pcs').val());
                            fivehundred = parseInt($('#500pcs').val());
                            twohundred =parseInt($('#200pcs').val());
                            onehundred = parseInt($('#100pcs').val());
                            fifty = parseInt($('#50pcs').val());
                            twenty = parseInt($('#20pcs').val());
                            ten = parseInt($('#10pcs').val());
                            five = parseInt($('#5pcs').val());
                            one = parseInt($('#1pcs').val());
                
                            if(thousand!=""){
                                if(isNaN(thousand)){
                                }else{
                                    var amt = 1000*thousand;
                                    $('#1000amt').val(amt);
                                    compute(1000);
                                }
                            }
                
                            if(fivehundred!=""){
                                if(isNaN(fivehundred)){
                                }else{
                                    var amt = 500*fivehundred;
                                    $('#500amt').val(amt);
                                    compute(500);
                                }
                            }
                
                            if(twohundred!=""){
                                if(isNaN(twohundred)){
                                }else{
                                    var amt = 200*twohundred;
                                    $('#200amt').val(amt);
                                    compute(200);
                                }
                            }
                
                            if(onehundred!=""){
                                if(isNaN(onehundred)){
                                }else{
                                    var amt = 100*onehundred;
                                    $('#100amt').val(amt);
                                    compute(100);
                                }
                            }
                
                            if(fifty!=""){
                                if(isNaN(fifty)){
                                }else{
                                    var amt = 50*fifty;
                                    $('#50amt').val(amt);
                                    compute();
                                }
                            }
                
                            if(twenty!=""){
                                if(isNaN(twenty)){
                                }else{
                                    var amt = 20*twenty;
                                    $('#20amt').val(amt);
                                    compute(20);
                                }
                            }
                
                            if(ten!=""){
                                if(isNaN(ten)){
                                }else{
                                    var amt = 10*ten;
                                    $('#10amt').val(amt);
                                    compute(10);
                                }
                            }
                
                            if(five!=""){
                                if(isNaN(five)){
                                }else{
                                    var amt = 5*five;
                                    $('#5amt').val(amt);
                                    compute(5);
                                }
                            }
                            if(one!=""){
                                if(isNaN(one)){
                                }else{
                                    var amt = 1*one;
                                    $('#1amt').val(amt);
                                    compute(1);
                                }
                            }
                                          
                        });
                    </script>

                    <jsp:include page="WEB-INF/fragments/savedcollection.jsp"/>
                </c:if>

                <c:if test="${param.cat == 'allcoll'}">
                    <jsp:include page="WEB-INF/fragments/headofficecollection.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'allpayment'}">
                    <jsp:include page="WEB-INF/fragments/headofficepayment.jsp"/>

                </c:if>
                <c:if test="${param.cat == 'alldeposit'}">
                    <jsp:include page="WEB-INF/fragments/headofficedeposit.jsp"/>
                </c:if>
                <c:if test="${param.cat == 'sample'}">
                    <jsp:include page="WEB-INF/fragments/samplesearch.jsp"/>
                </c:if>
            </s:div>

        </s:div>
        <jsp:include page="WEB-INF/fragments/bottom.jsp"/>
    </s:div>
</body>
</html>
